package com.edu.exam.entity.teachingclass;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 教学班实体类
 * [所属模块] F-06 教学班管理模块
 * 对应数据库表：teaching_class
 *
 * 根据简化后的F-06模块设计，专注于教学班基础信息管理。
 * 支持教学班的创建、查询、更新、删除和状态管理。
 * 关联课程、教师、学生等核心信息。
 *
 * @author System
 * @version 3.0.0 (简化版)
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Table(name = "teaching_class")
public class TeachingClass {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @NotBlank(message = "教学班名称不能为空")
    @Size(max = 200, message = "教学班名称长度不能超过200个字符")
    @Column(name = "name", nullable = false, length = 200)
    private String name;

    @Size(max = 1000, message = "教学班描述长度不能超过1000个字符")
    @Column(name = "description", columnDefinition = "TEXT")
    private String description;

    @NotNull(message = "关联课程不能为空")
    @Column(name = "course_id", nullable = false)
    private Long courseId;

    @NotBlank(message = "学期不能为空")
    @Size(max = 20, message = "学期长度不能超过20个字符")
    @Column(name = "semester", nullable = false, length = 20)
    private String semester;

    @NotNull(message = "教学班容量不能为空")
    @Column(name = "capacity", nullable = false)
    private Integer capacity;

    @Column(name = "current_count", nullable = false)
    @Builder.Default
    private Integer currentCount = 0;

    @Column(name = "status", nullable = false, length = 20)
    @Builder.Default
    private String status = "PLANNED";

    @Size(max = 50, message = "创建人长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    @CreatedDate
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", length = 50)
    private String updatedBy;

    @LastModifiedDate
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;
}